<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace suifeng\builder\table\column;

use suifeng\builder\table\Column;

class Text extends Column
{
    /**
     * 字段。
     *
     * @var unknown
     */
    public $field;

    /**
     * 构造方法。
     *
     * @param string $config
     */
    public function __construct($config = array())
    {
        parent::__construct($config);

        if (empty($this->field)) {
            if ($this->name) {
                $this->field = $this->name;
            }
        }
    }

    /**
     * 获取单元格内容。
     *
     * @param unknown $row
     * @return unknown|string
     */
    protected function _fetch_cell_content($row)
    {
        $value = $this->_get_cell_value($row);
        return $value ? $value : '&nbsp;';
    }

    /**
     * 获取单元格的值。
     *
     * @param unknown $row
     * @return NULL|unknown
     */
    protected function _get_cell_value($row)
    {
        if (isset($row[$this->field])) {
            $value = $row[$this->field];
        } else {
            $value = null;
        }
        return $value;
    }
}
